package business;

import java.util.ArrayList;

import bean.Customer;
import database.DB_Handler;
import exceptions.IdNotFoundException;


/**
 * Business Logic for handling Customer Operations
 * @author Martin Schophaus
 *
 */
public class BL_Customer {
	
	/**
	 * Adds a customer to the database
	 * @param customer customer that should be added to the database
	 * @return Returns the same customer but with it's new id which is created by the database
	 */
	public Customer addCustomer(Customer customer) {
		return DB_Handler.getInstance().addCustomer(customer);
	}
	
	/**
	 * @return returns an ArrayList with all customers from the database
	 */
	public ArrayList<Customer> getAll() {
		return DB_Handler.getInstance().getAllCustomer();
	}
	
	/**
	 * @param id the customer id of the customer that should be selected from the database
	 * @return returns the customer with the given id
	 * @throws IdNotFoundException if the given id is not found in the database
	 */
	public Customer getById(int id) throws IdNotFoundException {
		return DB_Handler.getInstance().getCustomer(id);
	}
	
	/**
	 * Updates an existing customer in the database
	 * @param customer The customer that should be updated in the database
	 */
	public void update(Customer customer) {
		DB_Handler.getInstance().updateCustomer(customer);
	}
}